﻿using System.Collections.Generic;
using System.Linq;
using WholesaleOnline.Model;

namespace WholesaleOnline.Controller.Extension
{
    public static class BasketExtensionMethod
    {
        public static IEnumerable<dynamic> ConvertToBasketJsonModel(this IEnumerable<WoBasket> baskets)
        {
            return  baskets.Select(b => new
            {
                sellerName = b.Seller.Name,
                items = b.Items.Select(i => new
                {
                    id = i.Id,
                    name = i.Product.Name,
                    img = i.Product.Img,
                    price = i.Product.Price,
                    qty = i.Quantity,
                    totalPrice = i.TotalPrice
                }),
                totalPrice = b.TotalPrice
            });
        }
    }
}
